package com.bawei.attendance

import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.attendance.databinding.ActivityAttendanceBinding
import com.bawei.common.RouterPath
import com.bawei.common.base.BaseActivity
import dagger.hilt.android.AndroidEntryPoint

@Route(path = RouterPath.PATH_ATTENDANCE)
@AndroidEntryPoint
class AttendanceActivity : BaseActivity<ActivityAttendanceBinding>() {

    @Autowired
    @JvmField
    var moduleType: String = "11"

    override fun getLayoutId(): Int = R.layout.activity_attendance

    override fun initViews() {
        ARouter.getInstance().inject(this)
        initFragment()
        //设置返回按钮事件
        mDataBinding.includePageTitle.ivBack.setOnClickListener {
            this@AttendanceActivity.finish()
        }
    }

    /**
     * 初始化Fragment
     */
    private fun initFragment(){
        when(moduleType){
            "11" -> {
                mDataBinding.includePageTitle.tvTitle.text = "签到"
                commitFragment(SignInFragment.newInstance(), moduleType)
            }
            "12" -> {
                mDataBinding.includePageTitle.tvTitle.text = "考勤管理"
                commitFragment(ManageFragment.newInstance(), moduleType)
            }
        }
    }

    /**
     * 提交Fragment到Activity中
     */
    private fun commitFragment(targetFragment: Fragment, fragmentTag: String){
        //1.获取FragmentManager
        var fragmentManager = supportFragmentManager
        //2.开启事务
        var fragmentTransaction = fragmentManager.beginTransaction()
        //3.提交事务
        fragmentTransaction.replace(R.id.fragment_container, targetFragment, fragmentTag)
        fragmentTransaction.commit()
    }

}